//
//  SearchView.swift
//  jingxin
//
//  Created by Yuki on 2020/8/7.
//  Copyright © 2020 Zl. All rights reserved.
//  搜索框

import UIKit

typealias ClickBlock = ()->Void;//点击自己的事件
typealias ClickBlockContenParam = (_ searchView:SearchView)->Void;//点击自己传参

class SearchView: BaseView {
    var clickBlock :ClickBlock?;//闭包点击事件
    var clickBlockContentParam :ClickBlockContenParam?;
    
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        buildUI();
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder);
        buildUI();
    }
    
    //MARK:创建界面
    private func buildUI(){
        /**  图片  **/
        self.addSubview(self.searchImgView);
        self.searchImgView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 20*width(), height: 20*height()));
            make.centerY.equalTo(self);
            make.right.equalTo(-17*width());
        };
        
        /**  输入框  **/
        self.addSubview(self.inpuTextFiled);
        self.inpuTextFiled.snp_makeConstraints { (make) in
            make.left.equalTo(17*width());
            make.centerY.equalTo(self);
            make.right.equalTo(self.searchImgView.snp_left).offset(-5*width());
        }
        
        /**  点击事件  **/
        self.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(clickSelf)));
    }
    
    //MARK:set方法
    var placeholderStr:String?{
        didSet{
            self.inpuTextFiled.placeholder = placeholderStr;
        }
    }
    var canEdit:Bool?{
        didSet{
            self.inpuTextFiled.isEnabled = canEdit ?? false;
        }
    }
    
    //MARK:点击事件
    @objc func clickSelf(){
        if self.clickBlockContentParam != nil{
            self.clickBlockContentParam?(self);
        }
    }
    
    //MARK:懒加载
    /**  输入框  **/
    lazy var inpuTextFiled :UITextField = {
        var  inpuTextFiled = UITextField.init();
        inpuTextFiled.font = .systemFont(ofSize: 14*height(), weight: .regular);
        return inpuTextFiled;
    }()
    
    /**  放大镜  **/
    lazy var searchImgView :UIImageView = {
        var searchImgView = createImgView("search_ico");
        return searchImgView;
    }()
   
}
